******************************************************************************
* Replication for 'Structural adjustment, alienation, and protest'  
* 
* July 10, 2022
* Contact: bernhard.reinsberg@glasgow.ac.uk
*
******************************************************************************

* Data 
******************************************************************************

  use "SSR-replication", clear 
  
  egen bp=rowtotal(b_strikes b_riots b_antigov)
  lab var bp "Protests"
  g lnbp=ln(1+bp)
  replace lnbp=. if b_strikes==.
    
  g MS5=.
  forvalues y=1981/2015{
	g imfnn=IMFnn
	replace imfnn=. if year>=`y' | year<`y'-5
	egen nimfnn=mean(imfnn), by(cid)
	replace MS5=nimfnn if year==`y'
	drop imfnn nimfnn
  }
  
  foreach x in TOT FP LAB SOE PRI EXT{
    g lnBA2`x'=ln(1+BA2`x')
  }
  g lncBATOT=ln(1+cBATOT)
 
  g lnliq=ln(imf_liq)
  g L1lnliq=l.lnliq
  
  g lngdppc=asinh(gdppc_WDI)
  g lncpi=asinh(infl_cpi)
  replace crisis_LV=0 if crisis_LV==.  
  g left0=(dpi_erlc==3 |dpi_gprlc1==3)
  
  egen reg_y=sum(bp), by(regid year)
  replace reg_y=reg_y-bp if bp!=.
  egen reg_n=count(cow), by(regid year)
  replace reg_y=reg_y/reg_n
  lab var reg_y "Regional protest"
  
  g thp1=(year-1979)
  g thp2=(year-1979)^2-1
  g thp3=(year-1979)^3-3*(year-1979)
	
  qui xi:reg bp i.regid i.incid i.year i.cid
  cmp setup 
  set matsize 800
  

* Distributional plots
***********************************************************************  
  
  ** Figure 1 **
  preserve
    keep lnbp bp IMFnn cid year
	g i=1
	replace bp=. if lnbp==.
    collapse (sum)i, by(bp IMFnn)
	drop if IMFnn==.
	reshape wide i, i(bp) j(IMFnn)
	edit
  restore
 
  ttest bp if lnbp!=., by(IMFnn) une
  
  ** Figure A1 **
  hist bp if lnbp!=., scheme(s1mono) percent xtitle(Protests) note(Distribution of protests -- all observations)
  graph export "bp_all.png", replace width(1000)
  hist bp if bp>0 & lnbp!=., scheme(s1mono) percent xtitle(Protests) note(Distribution of protests -- positive protest numbers only)
  graph export "bp_all_pos.png", replace width(1000)
  
  
* Main results 
***********************************************************************  
  
  global X0 lngdppc pop_urb v2x_hor v2x_ver KOFTrGIdf reg_y
  global X1 lncpi crisis_LV reserves_WDI 
    
  egen imfc=mean(IMFnn), by(cid)
  g imft=L1lnliq
  g imftc=imfc*imft
  
  egen mba=mean(BA2TOT), by(cid)
  g lnmba=ln(1+mba)
  g tba=L1lnliq
  g batc=lnmba*tba
  
  global ZFE imftc imft imfc _Icid* _Iyear*
  global Z s_unga3g7
  
  mat Diag=J(7,4,0)

  
* Unconditional program effect 

  qui xtreg lnbp IMFnn $X1 $X0 thp*, fe cl(cid)
  est store a1
   mat Diag[1,1]=e(N)
   mat Diag[1,2]=e(N)
   mat Diag[2,1]=e(r2_w)
   mat Diag[2,2]=e(r2_w)
  qui cmp (lnbp=IMFnn $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators(1 $cmp_probit) ro cl(cid) iterate(40)
  est store a2
   mat Diag[3,2]=e(N2)
   qui probit IMFnn $Z $X1 $X0 thp*
   mat Diag[4,2]=e(r2_p)
  qui xtreg lnbp IMFnn lnBA2TOT $X1 $X0 thp*, fe cl(cid) 
  est store a3
   mat Diag[1,3]=e(N)
   mat Diag[2,3]=e(r2_w)
   mat Diag[1,4]=e(N)
   mat Diag[2,4]=e(r2_w)
  qui cmp (lnbp=IMFnn lnBA2TOT $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*) (lnBA2TOT=batc lnmba tba $X1 $X0 thp* _Icid*), indicators(1 $cmp_probit 1) ro cl(cid) iterate(40)
  est store a4
   mat Diag[3,4]=e(N2)
   mat Diag[5,4]=e(N3)
   test [lnBA2TOT]batc
   mat Diag[7,4]=r(chi2)
   qui probit IMFnn $Z $X1 $X0 thp*
   mat Diag[4,4]=e(r2_p)
   qui xtreg lnBA2TOT batc mba tba $X1 $X0 thp*, fe 
   mat Diag[6,4]=e(r2_w)
    
  ** Table 1 **
  estout a*, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li Diag 

  
* Effects of different program conditions 

  mat DiagCo=J(8,5,0)
  local t=1
  
  foreach x in BA2FP BA2LAB BA2SOE BA2EXT BA2PRI {
  di "`x':"   
  g x=ln`x'
  qui egen ivc=mean(`x'), by(cid)
  qui g lnivc=ln(1+ivc)
  qui g ivt=L1lnliq
  qui g ivtc=lnivc*ivt
  
  qui xtreg lnbp x IMFnn $X1 $X0 thp*, fe cl(cid)
  est store b1`t'
  
  qui cmp (lnbp=x IMFnn $X1 $X0 _Icid* thp*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40) 
  est store b2`t'
  
  qui cmp (lnbp=x IMFnn $X1 $X0 _Icid* thp*) (x=ivtc ivt lnivc $X1 $X0 _Icid* thp*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_cont $cmp_probit) ro cl(cid) iterate(40) 
   est store b3`t'
   mat DiagCo[1,`t']=e(N1)
   mat DiagCo[3,`t']=e(N2)
   mat DiagCo[6,`t']=e(N3)
   qui test [x]ivtc
   mat DiagCo[5,`t']=r(chi2)
   qui test [IMFnn]s_unga3
   mat DiagCo[8,`t']=r(chi2)
   qui xtreg x ivtc ivt lnivc $X1 $X0 thp*, fe 
   mat DiagCo[4,`t']=e(r2_w)
   qui xtreg lnbp x IMFnn $X1 $X0 thp*, fe 
   mat DiagCo[2,`t']=e(r2_w)
   qui probit IMFnn $Z $X1 $X0 thp*
   mat DiagCo[7,`t']=e(r2_p)
  
  local t=`t'+1
  drop *ivc ivtc ivt x 
  }

  ** Table 2 **
  estout b*1, keep(x IMFnn) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  estout b*2, keep(x IMFnn) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  estout b*3, keep(x IMFnn) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  estout b*4, keep(x IMFnn) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  estout b*5, keep(x IMFnn) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  mat li DiagCo


* Effect heterogeneity: Left-wing governments

  g imfleft0=IMFnn*left0
  
  mat Diag=J(8,4,0)
  qui xtreg lnbp IMFnn left0 imfleft0 $X1 $X0 thp*, fe cl(cid)
  est store c1
   mat Diag[1,1]=e(N)
   mat Diag[2,1]=e(r2_w)
   mat Diag[1,2]=Diag[1,1]
   mat Diag[2,2]=Diag[2,1]
  qui cmp (lnbp=IMFnn left0 imfleft0 $X1 $X0 thp* _Icid*) (IMFnn=$Z left0 $X1 $X0 thp*), indicators(1 $cmp_probit) ro cl(cid) iterate(40)
  est store c2
   qui test [IMFnn]$Z 
   mat Diag[5,2]=r(chi2)
   mat Diag[3,2]=e(N2)
   qui probit IMFnn $Z left0 $X1 $X0 thp*
   mat Diag[4,2]=e(r2_p)
   mat Diag[3,4]=Diag[3,2]
   mat Diag[4,4]=Diag[4,2]
  qui xtreg lnbp IMFnn lnBA2TOT left0 imfleft0 $X1 $X0 thp*, fe cl(cid) 
  est store c3
   mat Diag[1,3]=e(N)
   mat Diag[2,3]=e(r2_w)
   mat Diag[1,4]=Diag[1,3]
   mat Diag[2,4]=Diag[2,3]
  qui cmp (lnbp=IMFnn lnBA2TOT left0 imfleft0 $X1 $X0 thp* _Icid*) (IMFnn=$Z left0 $X1 $X0 thp*) (lnBA2TOT=batc lnmba tba left0 $X1 $X0 thp* _Icid*), indicators(1 $cmp_probit 1) ro cl(cid) iterate(40)
  est store c4
   mat Diag[7,4]=e(N3)
   qui test [IMFnn]$Z
   mat Diag[5,4]=r(chi2)
   qui test [lnBA2TOT]batc
   mat Diag[8,4]=r(chi2)
   qui xtreg lnBA2TOT batc lnmba tba left0 $X1 $X0 thp*, fe
   mat Diag[6,4]=e(r2_w)
    
  ** Table 3 **
  estout c*, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li Diag 
  
  ** Predictions **
  qui reg lnbp IMFnn##left0 $X1 $X0 thp* _Icid*, cl(cid)
  margins IMFnn#left0, vce(uncond)


* Effect heterogeneity: Recidivist borrowers
  
  g imfms5=IMFnn*MS5
  
  qui xtreg lnbp IMFnn imfms5 MS5 $X1 $X0 thp*, fe cl(cid)
  est store d1
   mat Diag[1,1]=e(N)
   mat Diag[2,1]=e(r2_w)
   mat Diag[1,2]=Diag[1,1]
   mat Diag[2,2]=Diag[2,1]
  qui cmp (lnbp=IMFnn MS5 imfms5 $X1 $X0 thp* _Icid*) (IMFnn=$Z MS5 $X1 $X0 thp*), indicators(1 $cmp_probit) ro cl(cid) iterate(40)
  est store d2
   qui test [IMFnn]$Z 
   mat Diag[5,2]=r(chi2)
   mat Diag[3,2]=e(N2)
   qui probit IMFnn $Z MS5 $X1 $X0 thp*
   mat Diag[4,2]=e(r2_p)
   mat Diag[3,4]=Diag[3,2]
   mat Diag[4,4]=Diag[4,2]
  qui xtreg lnbp IMFnn lnBA2TOT MS5 imfms5 $X1 $X0 thp*, fe cl(cid) 
  est store d3
   mat Diag[1,3]=e(N)
   mat Diag[2,3]=e(r2_w)
   mat Diag[1,4]=Diag[1,3]
   mat Diag[2,4]=Diag[2,3]
  qui cmp (lnbp=IMFnn lnBA2TOT MS5 imfms5 $X1 $X0 thp* _Icid*) (IMFnn=$Z MS5 $X1 $X0 thp*) (lnBA2TOT=batc lnmba tba MS5 $X1 $X0 thp* _Icid*), indicators(1 $cmp_probit 1) ro cl(cid) iterate(40)
  est store d4
   mat Diag[7,4]=e(N3)
   qui test [IMFnn]$Z
   mat Diag[5,4]=r(chi2)
   qui test [lnBA2TOT]batc
   mat Diag[8,4]=r(chi2)
   qui xtreg lnBA2TOT batc mba tba MS5 $X1 $X0 thp*, fe
   mat Diag[6,4]=e(r2_w)
    
  ** Table 4 **
  estout d*, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li Diag 
  
  ** Predictions (Figure 2) **
  est restore d1
  grinter IMFnn, const(MS5) inter(imfms5) scheme(s1mono) kdens
  margins, at(IMF=(0 1) MS5=(0.27 1)) 

  
* Fiscal adjustment measure (Guimaraes & Ladeira 2021)

  preserve 
  
  use "SSR-replication-programs", clear
  
  qui xi:reg lnbp1 i.approval 
  qui xtpqml bp1 prefb rfa1 years _Iapproval*, fe i(countryid) cl(countryid)
  est store q21
  qui xtpqml bp1 prefb rfa1 numb* years _Iapproval*, fe i(countryid) cl(countryid)
  est store q22
  qui xtpqml bp1 prefb rfa1 numb* gdpg pop15 cab elec1 years _Iapproval*, fe i(countryid) cl(countryid)
  est store q23
  
  ** Table 4 **
  estout q2*, drop(_I*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3)))) stats(N ll, fmt(0 1))
  
  restore
  

* Robustness tests
*****************************************************************************
  
* Variables 
  
  qui estpost su bp IMFnn BA2TOT BA2FP BA2LAB BA2SOE BA2EXT BA2PRI $X1 $X0 $Z
  
  ** Table A1 **
  esttab ., cells("count mean sd min max") noobs
  
  
* Year FE

  qui xtreg lnbp IMFnn $X1 $X0 _Iyear*, fe cl(cid)
  est store ya1
   mat Diag[1,1]=e(N)
   mat Diag[2,1]=e(r2_w)
   mat Diag[1,2]=Diag[1,1]
   mat Diag[2,2]=Diag[2,1]
  qui cmp (lnbp=IMFnn $X1 $X0 _Iyear* _Icid*) (IMFnn=$Z $X1 $X0 _Iyear*), indicators(1 $cmp_probit) ro cl(cid) iterate(40)
  est store ya2
   qui test [IMFnn]$Z 
   mat Diag[5,2]=r(chi2)
   mat Diag[3,2]=e(N2)
   qui probit IMFnn $Z $X1 $X0 _Iyear*
   mat Diag[4,2]=e(r2_p)
   mat Diag[3,4]=Diag[3,2]
   mat Diag[4,4]=Diag[4,2]
  qui xtreg lnbp IMFnn lnBA2TOT $X1 $X0 _Iyear*, fe cl(cid) 
  est store ya3
   mat Diag[1,3]=e(N)
   mat Diag[2,3]=e(r2_w)
   mat Diag[1,4]=Diag[1,3]
   mat Diag[2,4]=Diag[2,3]
  qui cmp (lnbp=IMFnn lnBA2TOT $X1 $X0 _Iyear* _Icid*) (IMFnn=$Z $X1 $X0 _Iyear*) (lnBA2TOT=batc lnmba tba $X1 $X0 _Iyear* _Icid*), indicators(1 $cmp_probit 1) ro cl(cid) iterate(40)
  est store ya4
   mat Diag[7,4]=e(N3)
   qui test [IMFnn]$Z
   mat Diag[5,4]=r(chi2)
   qui test [lnBA2TOT]batc
   mat Diag[8,4]=r(chi2)
   qui xtreg lnBA2TOT batc mba tba MS5 $X1 $X0 _Iyear*, fe
   mat Diag[6,4]=e(r2_w)
    
  ** Table A2 **
  estout ya*, drop(_cons _I* ) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li Diag 
  
  
* Political grievances at different lags   
  
  mat DiagA=J(4,4,0)
  
  forvalues t=1/2{

  global LX0 l`t'.lngdppc l`t'.pop_urb l`t'.v2x_hor l`t'.v2x_ver l`t'.KOFTrGIdf l`t'.reg_y 
  global LX1 l`t'.lncpi l`t'.crisis_LV l`t'.reserves
  global LZ l`t'.s_unga3g7
  di "Lag `t':"

  qui g imf=l`t'.IMFnn
  qui g imfleft=imf*l`t'.left0 
  qui g imfrec=imf*l`t'.MS5
  
  qui cmp (lnbp=imf imfleft l`t'.left0 $LX1 $LX0 _Icid* thp*) (imf=$LZ $LX1 $LX0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) difficult iterate(30)
   est store a1`t'_left
   qui xtreg lnbp l`t'.IMFnn imfleft l`t'.left0 $LX1 $LX0 thp* if e(sample), fe 
   mat DiagA[1,`t']=e(N)
   mat DiagA[2,`t']=e(r2_w)
   qui probit l`t'.IMFnn $LZ $LX0 $LX1 thp*
   mat DiagA[3,`t']=e(N)
   mat DiagA[4,`t']=e(r2_p)
   
  qui cmp (lnbp=imf imfrec l`t'.MS5 $LX1 $LX0 _Icid* thp*) (imf=$LZ $LX1 $LX0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(30)
   est store a1`t'_rec
   qui xtreg lnbp l`t'.IMFnn imfrec l`t'.MS5 $LX1 $LX0 thp* if e(sample), fe 
   mat DiagA[1,2+`t']=e(N)
   mat DiagA[2,2+`t']=e(r2_w)
   qui probit l`t'.IMFnn $LZ $LX1 $LX0 thp*
   mat DiagA[3,2+`t']=e(N)
   mat DiagA[4,2+`t']=e(r2_p)
   
   drop imf* 
  }
  
  ** Table A3 **
  estout a1*left a1*rec, drop(_cons thp* _I*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li DiagA
  

* Within-program dynamics 
  
  g onset=IMFnn==1 & l.IMFnn==0
  g oncont=IMFnn==1 & l.IMFnn==1
  g onforw=IMFnn==0 & f.IMFnn==1
  
  mat Diag=J(6,3,0)
  
  su onset oncont onforw
  qui xtreg lnbp onset oncont onforw $X1 $X0 thp*, fe cl(cid)
  est store ion1
  qui xtreg lnbp onset##left0 oncont##left0 onforw##left0 $X1 $X0 thp*, fe cl(cid)
  est store ion2
  qui xtreg lnbp onset##c.MS5 oncont##c.MS5 onforw##c.MS5 $X1 $X0 thp*, fe cl(cid)
  est store ion3
  
  ** Table A4 **
  estout ion*, drop(_cons *0.* th*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2_w, fmt(0 3))
  
 
* Disaggregate Banks measures

  mat DiagD=J(4,6,0)
  local m=1
  
  foreach y in b_strikes b_riots b_antigov{
  
    qui g lny=ln(1+`y')
    qui g imfleft=IMFnn*left0
    qui g imfrec=IMFnn*MS5
 
  qui cmp (lny=IMFnn imfleft left0 $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) difficult iterate(30)
   est store xb1`m'
   qui xtreg lny IMFnn left0 imfleft $X1 $X0 thp* if e(sample), fe 
   mat DiagD[1,`m']=e(N)
   mat DiagD[3,`m']=e(r2_w)
   qui probit IMFnn $Z $X1 $X0 thp* 
   mat DiagD[2,`m']=e(N)
   mat DiagD[4,`m']=e(r2_p)

  qui cmp (lny=IMFnn imfrec MS5 $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) difficult iterate(30)
   est store xb2`m'
   qui xtreg lny IMFnn imfrec MS5 $X1 $X0 thp* if e(sample), fe 
   mat DiagD[1,3+`m']=e(N)
   mat DiagD[3,3+`m']=e(r2_w)
   qui probit IMFnn $Z $X1 $X0 thp* 
   mat DiagD[2,3+`m']=e(N)
   mat DiagD[4,3+`m']=e(r2_p)
   
  local m=`m'+1
  drop lny imf*
  di "`y'."
  }

  ** Table A5 **
  estout xb1*, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  estout xb2*, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  mat li DiagD

	
* All conditions at the same time 

  mat Diag=J(4,4,0)
  qui cmp (lnbp=lnBA2FP lnBA2LAB lnBA2SOE lnBA2EXT lnBA2PRI IMFnn $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40)
   est store xc31
   mat Diag[1,1]=e(N1)
   mat Diag[3,1]=e(N2)
   qui xtreg lnbp lnBA2FP lnBA2LAB lnBA2SOE lnBA2EXT lnBA2PRI IMFnn $X1 $X0 thp*, fe
   mat Diag[2,1]=e(r2_w)
   qui probit IMFnn $X1 $X0 thp*  $Z
   mat Diag[4,1]=e(r2_p)
   
   foreach x in FP LAB SOE EXT PRI{
     qui egen ivc=mean(BA2`x'), by(cid)
	 qui g lnivc=ln(1+ivc)
	 qui g iv=ivc*L1lnliq
	 qui xtreg lnBA2`x' iv lnivc L1lnliq $X1 $X0 thp*, fe 
	 qui predict xhat`x', xb
	 drop iv *ivc
	 }
  qui cmp (lnbp=xhat* IMFnn $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40)
   est store xc32
   mat Diag[1,2]=e(N1)
   mat Diag[3,2]=e(N2)
   qui xtreg lnbp xhat* IMFnn $X1 $X0 thp*, fe
   mat Diag[2,2]=e(r2_w)
   qui probit IMFnn $X1 $X0 thp*  $Z
   mat Diag[4,2]=e(r2_p)
  
  g mod=left0
  g xmodimf=IMFnn*left0
  qui cmp (lnbp=xhat* IMFnn xmodimf mod $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40)
   est store xc33 
   mat Diag[1,3]=e(N1)
   mat Diag[3,3]=e(N2)
   qui xtreg lnbp xhat* IMFnn xmodimf mod $X1 $X0 thp*, fe
   mat Diag[2,3]=e(r2_w)
   qui probit IMFnn $X1 $X0 thp*  $Z
   mat Diag[4,3]=e(r2_p)
	
  replace mod=MS5
  replace xmodimf=IMFnn*MS5
  qui cmp (lnbp=xhat* IMFnn xmodimf mod $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40)
   est store xc35 
   mat Diag[1,4]=e(N1)
   mat Diag[3,4]=e(N2)
   qui xtreg lnbp xhat* xmodimf mod $X1 $X0 thp*, fe
   mat Diag[2,4]=e(r2_w)
   qui probit IMFnn $X1 $X0 thp*  $Z
   mat Diag[4,4]=e(r2_p)
   drop mod xmodimf 
   drop xhat*

  ** Table A6 **
  estout xc3*, drop(_cons _I* th*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li Diag 
  
  
* Implementation-discounted conditions

  qui egen mtot=mean(cBATOT), by(cid)
  qui g lnmtot=ln(1+mtot)
  qui g mttot=lnmtot*L1lnliq
  mat D=J(7,3,0)

  qui cmp (lnbp=IMFnn lncBATOT $X1 $X0 thp* _Icid*) (lncBATOT=mttot lnmtot L1lnliq $X1 $X0 thp* _Icid*) (IMFnn=$Z $X1 $X0 thp*), indicators(1 1 $cmp_probit) ro cl(cid)
  est store ba1 
   mat D[1,1]=e(N1)
   mat D[3,1]=e(N2)
   mat D[5,1]=e(N3)
   qui test [lncBATOT]mttot
   mat D[7,1]=r(chi2)
   qui xtreg lnbp IMFnn mttot lnmtot L1lnliq $X1 $X0 thp*, fe 
   mat D[2,1]=e(r2_w)
   qui probit IMFnn $X1 $X0 thp* $Z
   mat D[4,1]=e(r2_p)
   qui xtreg lncBATOT mttot lnmtot L1lnliq $X1 $X0 thp*, fe 
   mat D[6,1]=e(r2_w)
   
  g imfmod=IMFnn*left0
  g mod=left0 
   
  qui cmp (lnbp=IMFnn imfmod mod lncBATOT $X1 $X0 thp* _Icid*) (lncBATOT=mttot lnmtot L1lnliq $X1 $X0 mod thp* _Icid*) (IMFnn=$Z $X1 $X0 thp* mod), indicators(1 1 $cmp_probit) ro cl(cid)
  est store ba2
  mat D[1,2]=e(N1)
   mat D[3,2]=e(N2)
   mat D[5,2]=e(N3)
   qui test [lncBATOT]mttot
   mat D[7,2]=r(chi2)
   qui xtreg lnbp IMFnn mttot lnmtot L1lnliq mod imfmod $X1 $X0 thp*, fe 
   mat D[2,2]=e(r2_w)
   qui probit IMFnn $X1 $X0 thp* $Z mod
   mat D[4,2]=e(r2_p)
   qui xtreg lncBATOT mttot lnmtot L1lnliq $X1 $X0 thp* mod, fe 
   mat D[6,2]=e(r2_w)
   
  replace imfmod=IMFnn*MS5
  replace mod=MS5
   
  qui cmp (lnbp=IMFnn imfmod mod lncBATOT $X1 $X0 thp* _Icid*) (lncBATOT=mttot lnmtot L1lnliq $X1 $X0 mod thp* _Icid*) (IMFnn=$Z $X1 $X0 thp* mod), indicators(1 1 $cmp_probit) ro cl(cid)
  est store ba3
   mat D[1,3]=e(N1)
   mat D[3,3]=e(N2)
   mat D[5,3]=e(N3)
   qui test [lncBATOT]mttot
   mat D[7,3]=r(chi2)
   qui xtreg lnbp IMFnn mttot lnmtot L1lnliq $X1 $X0 thp* mod imfmod, fe 
   mat D[2,3]=e(r2_w)
   qui probit IMFnn $X1 $X0 thp* $Z mod
   mat D[4,3]=e(r2_p)
   qui xtreg lncBATOT mttot lnmtot L1lnliq $X1 $X0 thp* mod, fe 
   mat D[6,3]=e(r2_w)
   
   drop imfmod mod
   
  ** Table A7 **
  estout ba*, drop(_cons _I* th*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))  
  mat li D   

  
* PQML 

  mat ADiag=J(4,4,0)
  local m=1
  
  foreach z in left0 MS5{
  
  di "`z'"
  qui g mod=`z'
  qui g xmodimf=IMFnn*`z'
  
  qui xtpqml lnbp IMFnn xmodimf mod $X1 $X0 thp*, fe i(cid) cl(cid)
   est store pp1`m'
   mat ADiag[1,2*`m'-1]=e(N)
   qui xtreg lnbp mod IMFnn xmodimf $X1 $X0 thp*, fe 
   mat ADiag[2,2*`m'-1]=e(r2_w)
   
  qui treatreg lnbp IMFnn xmodimf mod $X1 $X0 thp* _Icid*, treat(IMFnn=$X1 $X0 thp* $Z) twostep hazard(imr) 
  qui xtpqml lnbp IMFnn xmodimf mod imr $X1 $X0 thp*, fe i(cid) cl(cid)
   est store pp2`m'
   mat ADiag[1,2*`m']=e(N)
   qui xtreg lnbp IMFnn xmodimf mod imr $X1 $X0 thp*, fe 
   mat ADiag[2,2*`m']=e(r2_w)
   qui probit IMFnn $X1 $X0 thp* $Z if imr!=.
   mat ADiag[3,2*`m']=e(N)
   mat ADiag[4,2*`m']=e(r2_p)
  
  drop imr xmod* mod
  local m=`m'+1
}
   
  ** Table A8 **
  estout pp*, drop( thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li ADiag  

  
* Alternative explanations: What left-wing government may mean

  mat ADiag=J(10,5,0)
  local m=1

  foreach z in left0 MS5{
  
  di "`z'"
  qui g mod=`z'
  qui g xmodimf=IMFnn*`z'
  
  local t=1
  foreach v in s_unga3g7 tottax lncpi crisis_LV capacity {
  
  qui g xvimf=IMFnn*`v'
  
  qui cmp (lnbp=IMFnn xmodimf mod xvimf `v' $X1 $X0 thp* _Icid*) (IMFnn=$Z `v' $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40) 
   est store ot`t'`m' 
   mat ADiag[1+5*(`m'-1),`t']=e(N1)
   mat ADiag[3+5*(`m'-1),`t']=e(N2)
   qui probit IMFnn $Z $X1 $X0 thp* `v'
   mat ADiag[4+5*(`m'-1),`t']=e(r2_p)
   qui xtreg lnbp mod IMFnn xmodimf  xvimf `v' $X1 $X0 thp*, fe 
   mat ADiag[2+5*(`m'-1),`t']=e(r2_w)

   local t=`t'+1
   drop xvimf
   }
   local m=`m'+1
   drop xmodimf mod
  }

  
  ** Table A9 ** 
  estout ot11 ot21 ot31 ot41 ot51, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells(b(star fmt(3)) se(par fmt(3)))
  estout ot12 ot22 ot32 ot42 ot52, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells(b(star fmt(3)) se(par fmt(3)))
  mat li ADiag


* Alternative explanations: General political instability 

  replace irreg=. if irreg==-999
  mat ADiag=J(10,4,0)
  local m=1
  
  foreach z in left0 MS5{
  
  di "`z'"
  qui g mod=`z'
  qui g xmodimf=IMFnn*`z'
  
  local t=1
  foreach v in theta_mean irreg dpi_exelec coup_any{
   
  qui g imfv=IMFnn*`v'
  qui cmp (lnbp=IMFnn xmodimf mod imfv `v' $X1 $X0 thp* _Icid*) (IMFnn=$Z `v' $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40) 
   est store ac`t'`m' 
   mat ADiag[1+5*(`m'-1),`t']=e(N1)
   mat ADiag[3+5*(`m'-1),`t']=e(N2)
   qui probit IMFnn $Z $X1 $X0 thp* `v'
   mat ADiag[4+5*(`m'-1),`t']=e(r2_p)
   qui xtreg lnbp mod IMFnn xmodimf imfv `v' $X1 $X0 thp*, fe 
   mat ADiag[2+5*(`m'-1),`t']=e(r2_w)
  
  local t=`t'+1
  drop imfv
  }  
  drop xmod* mod
  local m=`m'+1
}
  
  ** Table A10 **
  estout ac*1, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  estout ac*2, drop(_cons _I* thp*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li ADiag
  

* Alternative explanations: Left-wing governments implement more reforms? 

  g int0=IMFnn*left0
   
  qui xtreg d.hf_efi l.hf_efi IMFnn##left0 _Iyear*, fe cl(cid)
  est store h11
  qui xtreg d.hf_efi l.hf_efi IMFnn##left0 $X1 _Iyear*, fe cl(cid)
  est store h12
  qui xtreg d.hf_efi l.hf_efi IMFnn##left0 $X1 $X0 _Iyear*, fe cl(cid)
  est store h13
  
  ** Table A11 **
  estout h1*, drop(_cons *year* *0.*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2_w, fmt(0 3))
  

* CNTS/NYT bias

  mat DiagX=J(8,3,0)
 
  qui cmp (lnbp=IMFnn lnNYT $X1 $X0 thp* _Icid*) (IMFnn=$Z lnNYT $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) difficult iterate(30)
   est store tn1x
   qui xtreg lnbp IMFnn lnNYT $X1 $X0 thp* if e(sample), fe 
   mat DiagX[1,1]=e(N)
   mat DiagX[2,1]=e(r2_w)
   qui probit IMFnn lnNYT $Z $X1 $X0 thp*
   mat DiagX[3,1]=e(N)
   mat DiagX[4,1]=e(r2_p)
     
  local m=1
  foreach z in left0 MS5{
    di "`z'"
    qui g mod=`z'
    qui g xmodimf=IMFnn*`z'
  
    qui cmp (lnbp=IMFnn xmodimf mod lnNYT $X1 $X0 thp* _Icid*) (IMFnn=$Z lnNYT $X1 $X0 thp*), indicators($cmp_cont $cmp_probit) ro cl(cid) iterate(40) 
     est store tn2x`m'
     mat DiagX[1,1+`m']=e(N1)
     mat DiagX[3,1+`m']=e(N2)
     qui probit IMFnn $Z lnNYT $X1 $X0 thp* 
     mat DiagX[2,1+`m']=e(r2_p)
     qui xtreg lnbp mod IMFnn xmodimf lnNYT $X1 $X0 thp*, fe 
     mat DiagX[4,1+`m']=e(r2_w)
   
    local m=`m'+1
	drop mod xmodimf
    }
 
  ** Table A12 **
  estout tn1x tn2x*, drop(_cons _I* th*) starlevels(° .1 * .05 ** .01 *** .001) cells((b(star fmt(3)) se(par fmt(3))))
  mat li DiagX 
  
  
  
  